import request from '../request';

import { UserInfo, UserToken } from '#/entity';

export interface LoginReq {
    username: string;
    password: string;
}

export interface RegisterReq extends LoginReq {
    email: string;
    phone: string;
}
export type SignInRes = UserToken & { user: UserInfo };

export interface ValidateReq {
    phone: string
}

export interface UpdateReq {
    avatar:File
}

export interface ResetReq{
    password:string
    phone: string,
    code:string
}

export enum UserApi {
    Login = '/user/login',
    Register = '/user/register',
    Logout = '/user/logout',
    Reset = '/user/reset',
    Update = "/user/update",
    Validate="/user/validate"
}

// 正常的封装封装
export const login = (data: LoginReq) => request.post<SignInRes>({ url: UserApi.Login, data });
export const register = (data: RegisterReq) => request.post({ url: UserApi.Register, data });
export const logout = () => request.get({ url: UserApi.Logout });
export const validate = (data:ValidateReq) => request.post({ url: UserApi.Validate, data })
export const reset = (data:ResetReq) => request.post({ url: UserApi.Reset, data })
export const update=(data:UpdateReq)=>request.post({url:UserApi.Update,data})

